
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */



#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif


#include "stm32l0xx_hal.h"






















void Error_Handler(void);






#define DC_DC_EN1_Pin GPIO_PIN_5
#define DC_DC_EN1_GPIO_Port GPIOA
#define DC_DC_EN2_Pin GPIO_PIN_6
#define DC_DC_EN2_GPIO_Port GPIOA
#define DC_5_0V_EN_Pin GPIO_PIN_7
#define DC_5_0V_EN_GPIO_Port GPIOA
#define NB_PW_EN_Pin GPIO_PIN_12
#define NB_PW_EN_GPIO_Port GPIOB
#define DIO0_RSTN1_Pin GPIO_PIN_13
#define DIO0_RSTN1_GPIO_Port GPIOB
#define DIO1_WK_UP1_Pin GPIO_PIN_14
#define DIO1_WK_UP1_GPIO_Port GPIOB
#define DIO2_AT1_Pin GPIO_PIN_15
#define DIO2_AT1_GPIO_Port GPIOB
#define NB_MCU_RESET_Pin GPIO_PIN_8
#define NB_MCU_RESET_GPIO_Port GPIOA
#define PSM_EINT3V3_Pin GPIO_PIN_12
#define PSM_EINT3V3_GPIO_Port GPIOA
#define MCU_LED0_Pin GPIO_PIN_6
#define MCU_LED0_GPIO_Port GPIOB
#define MCU_LED1_Pin GPIO_PIN_7
#define MCU_LED1_GPIO_Port GPIOB
#define MCU_POWKEY_Pin GPIO_PIN_8
#define MCU_POWKEY_GPIO_Port GPIOB



typedef int32_t  	s32;
typedef int16_t 	s16;
typedef int8_t  	s8;
typedef signed char	int8;
typedef unsigned long  	u32;
typedef unsigned short 	u16;
typedef unsigned char  	u8;
typedef unsigned long long u64 ;
typedef char c8 ;

typedef struct
{
	uint8_t	    dismount_sw;
	uint8_t	    gps14a_reed_sw;
	uint8_t	    water_pressure_sw;
	uint8_t	    water_dip_sw; 
	uint8_t	    door_sensor1_sw;       
  uint8_t	    door_sensor2_sw;
	
	uint16_t    Bat_Vdd_Val;              
	uint16_t 	  Water_Ref_Val;
	uint16_t	  Water_LevelVal;      
	uint16_t	  Water_PressureVal;   
	
  uint8_t	    sensorstate_change;
	uint8_t	    AlarmFlag;
	uint8_t			SignalStrength;
	uint8_t			ReportTime;
	
} measure_value; 



#define RTC_CLOCK_SOURCE_LSI

#ifdef RTC_CLOCK_SOURCE_LSI
  #define RTC_ASYNCH_PREDIV    0x7C
  #define RTC_SYNCH_PREDIV     0x0127
#endif



#define IMEI_Len 	15
extern	uint8_t BC26_IMEI[IMEI_Len+1];

#define	ICCID_Len	20
extern	uint8_t BC26_ICCID[ICCID_Len+1];


#define REC_LENGTH  1
#define MAX_REC_LENGTH  512

#define Nb_Mode    0  
#define Lora_Mode  1
#define LoRaWAN_Mode  2

#define	Uart_ReceBufLen		90
#define TRUE 1
#define FALSE 0

#define SUCCESS 0
#define ERROR 1



#define	ErrCode_Success		0
#define	ErrCode_Fail		1
#define	ErrCode_Busy		2
#define	ErrCode_ReceData	3

typedef enum 
{

	Fire_Hydrant_Mode   =1,  
	Water_Pressure_Mode =2,  
	Water_Level_Mode    =3,  
	Door_Sensor_Mode    =4,  
	Water_Dip_Mode   =5,  
	
}eDeviceMode;


#define	VREFINT_CAL_L		*(__IO uint8_t *)(0x1FF80078)
#define	VREFINT_CAL_H		*(__IO uint8_t *)(0x1FF80079)



#define LED0_ON 			HAL_GPIO_WritePin(MCU_LED0_GPIO_Port,MCU_LED0_Pin,GPIO_PIN_RESET)
#define LED0_OFF			HAL_GPIO_WritePin(MCU_LED0_GPIO_Port,MCU_LED0_Pin,GPIO_PIN_SET)

#define LED1_ON 			HAL_GPIO_WritePin(MCU_LED1_GPIO_Port,MCU_LED1_Pin,GPIO_PIN_RESET)
#define LED1_OFF			HAL_GPIO_WritePin(MCU_LED1_GPIO_Port,MCU_LED1_Pin,GPIO_PIN_SET)


#define BC26_POWKEY_H 		HAL_GPIO_WritePin(MCU_POWKEY_GPIO_Port,MCU_POWKEY_Pin,GPIO_PIN_SET)
#define BC26_POWKEY_L			HAL_GPIO_WritePin(MCU_POWKEY_GPIO_Port,MCU_POWKEY_Pin,GPIO_PIN_RESET)

#define BC26_EINT3V3_H 		HAL_GPIO_WritePin(PSM_EINT3V3_GPIO_Port,PSM_EINT3V3_Pin,GPIO_PIN_SET)
#define BC26_EINT3V3_L		HAL_GPIO_WritePin(PSM_EINT3V3_GPIO_Port,PSM_EINT3V3_Pin,GPIO_PIN_RESET)

#define BC26_Reset_H 			HAL_GPIO_WritePin(NB_MCU_RESET_GPIO_Port,NB_MCU_RESET_Pin,GPIO_PIN_SET)
#define BC26_Reset_L			HAL_GPIO_WritePin(NB_MCU_RESET_GPIO_Port,NB_MCU_RESET_Pin,GPIO_PIN_RESET)

#define NB_PW_ON 			    HAL_GPIO_WritePin(NB_PW_EN_GPIO_Port,NB_PW_EN_Pin,GPIO_PIN_RESET)
#define NB_PW_OFF			    HAL_GPIO_WritePin(NB_PW_EN_GPIO_Port,NB_PW_EN_Pin,GPIO_PIN_SET)

#define DC_DC1_ON 			  HAL_GPIO_WritePin(DC_DC_EN1_GPIO_Port,DC_DC_EN1_Pin,GPIO_PIN_RESET)
#define DC_DC1_OFF			  HAL_GPIO_WritePin(DC_DC_EN1_GPIO_Port,DC_DC_EN1_Pin,GPIO_PIN_SET)

#define DC_DC2_ON 			  HAL_GPIO_WritePin(DC_DC_EN2_GPIO_Port,DC_DC_EN2_Pin,GPIO_PIN_SET)
#define DC_DC2_OFF			  HAL_GPIO_WritePin(DC_DC_EN2_GPIO_Port,DC_DC_EN2_Pin,GPIO_PIN_RESET)

#define DC_5_0V_ON 			  HAL_GPIO_WritePin(DC_5_0V_EN_GPIO_Port,DC_5_0V_EN_Pin,GPIO_PIN_SET)
#define DC_5_0V_OFF			  HAL_GPIO_WritePin(DC_5_0V_EN_GPIO_Port,DC_5_0V_EN_Pin,GPIO_PIN_RESET)




#define  AT_LOW		        HAL_GPIO_WritePin(DIO2_AT1_GPIO_Port,DIO2_AT1_Pin,GPIO_PIN_RESET)
#define  AT_HIGH		      HAL_GPIO_WritePin(DIO2_AT1_GPIO_Port,DIO2_AT1_Pin,GPIO_PIN_SET)

#define  WAKE_UP_LOW		  HAL_GPIO_WritePin(DIO1_WK_UP1_GPIO_Port,DIO1_WK_UP1_Pin,GPIO_PIN_RESET)
#define  WAKE_UP_HIGH		  HAL_GPIO_WritePin(DIO1_WK_UP1_GPIO_Port,DIO1_WK_UP1_Pin,GPIO_PIN_SET)

#define  RSTn_LOW		      HAL_GPIO_WritePin(DIO0_RSTN1_GPIO_Port,DIO0_RSTN1_Pin,GPIO_PIN_RESET)
#define  RSTn_HIGH		    HAL_GPIO_WritePin(DIO0_RSTN1_GPIO_Port,DIO0_RSTN1_Pin,GPIO_PIN_SET)


#define  SETA_LOW         HAL_GPIO_WritePin(DIO1_WK_UP1_GPIO_Port,DIO1_WK_UP1_Pin,GPIO_PIN_RESET)
#define  SETA_HIGH		    HAL_GPIO_WritePin(DIO1_WK_UP1_GPIO_Port,DIO1_WK_UP1_Pin,GPIO_PIN_SET)



#define	 dismount_PORT					     GPIOA	
#define  dismount_PIN   				     GPIO_PIN_4
#define	 Get_Dismount_PIN_STATUS		 HAL_GPIO_ReadPin(dismount_PORT,dismount_PIN)


#define	 gps14a_PORT					       GPIOB	      
#define  gps14a_PIN   				       GPIO_PIN_3
#define	 gps14a_PIN_STATUS		       HAL_GPIO_ReadPin(gps14a_PORT,gps14a_PIN)



#define	 water_dip_PORT					     GPIOB	
#define  water_dip_PIN   				     GPIO_PIN_0
#define	 water_dip_PIN_STATUS		     HAL_GPIO_ReadPin(water_dip_PORT,water_dip_PIN)



#define	 door_sensor1_PORT					     GPIOB	
#define  door_sensor1_PIN   				     GPIO_PIN_0
#define	 door_sensor1_PIN_STATUS		     HAL_GPIO_ReadPin(door_sensor1_PORT,door_sensor1_PIN)

#define	 door_sensor2_PORT					     GPIOB	
#define  door_sensor2_PIN   				     GPIO_PIN_1
#define	 door_sensor2_PIN_STATUS		     HAL_GPIO_ReadPin(door_sensor2_PORT,door_sensor2_PIN)



#define	 fire_hydrant_PORT					     GPIOB	
#define  fire_hydrant_PIN   				     GPIO_PIN_0
#define	 fire_hydrant_PIN_STATUS		     HAL_GPIO_ReadPin(fire_hydrant_PORT,fire_hydrant_PIN)

void LED_blink(uint8_t time);




#ifdef __cplusplus
}
#endif

#endif 


